/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dsw2.Bl;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dsw2.Enumerations.TransactionStatus;
import mx.itsc.ds2.Dao.CourseDaoLocal;
import mx.itsc.ds2.model.Course;
import mx.itsc.ds2.model.Student;

/**
 *
 * @author Juan Carlos
 */
@Stateless
public class CourseBL implements CourseBLLocal {
    @EJB
    private CourseDaoLocal courseDao;

    @Override
    public TransactionStatus register(Course course) {
        if (courseDao.findDuplicity(course)) {
            return TransactionStatus.INCOMPLETO;
        }else{
            courseDao.create(course);
            return TransactionStatus.COMPLETO;
        }
    }

    @Override
    public TransactionStatus remove(Course course) {
        if (courseDao.find(course.getId()) == null || course.getId() == null) {
            return TransactionStatus.INCOMPLETO;
        } else {
            courseDao.remove(course);
            return TransactionStatus.COMPLETO;
        }
    }

    @Override
    public TransactionStatus modify(Course course) {
        if (courseDao.find(course.getId()) == null|| course.getId() == null) {
            return TransactionStatus.INCOMPLETO;
        } else {
            courseDao.edit(course);
            return TransactionStatus.COMPLETO;
        }
    }

    @Override
    public List<Course> findAll() {
        return courseDao.findAll();
    }

    @Override
    public Course findById(int idcourse) {
        return courseDao.find(idcourse);
    }

    @Override
    public List<Course> findByCourse(Student student) {
        List<Course> courseList = courseDao.findByCourse(student);
        List<Course> finalCourseList = new ArrayList<Course>();
        for (Course cl : courseList) {
            finalCourseList.add(cl);
        }
        
        return finalCourseList;
    }

    @Override
    public List<Course> findCourse(Course course) {
        List<Course> courseList = courseDao.findCourse(course);
        List<Course> finalCourseList = new ArrayList<Course>();
        for (Course course1 : courseList) {
            finalCourseList.add(course1);
        }
        return finalCourseList;
    }
    
    
    
}
